< previous page page_452 next page >

Page 452
Example program Reflect demonstrates the steps in performing a reflection across an arbitrary plane. It applies the transformation matrices used to reflect an object one at a time and shows the object after each step. When you run the program, you can use the left, right, up, and down arrow keys to change the program's viewing direction.
Rotation around an Arbitrary Line
You can follow similar steps to rotate an object around an arbitrary line.
1. Translate the line to the origin.
2. Rotate around the Z axis until the line lies in the Y-Z plane.
3. Rotate around the X axis until the line lies along the Y axis.
4. Rotate around the Y axis.
5. Reverse the second rotation.
6. Reverse the first rotation.
7. Reverse the translation.
Example program Rotate demonstrates the steps used to rotate an object around an arbitrary line. It applies the required transformations one at a time and shows the object after each step. When you run the program, you can use the left, right, up, and down arrow keys to change the program's viewing direction.
Subroutine m3LineRotate, included in module M3Ops.bas, initializes a single, combined transformation matrix for rotating around an arbitrary line.
e10a6a0a59f035e870d90cca05b85fce.gif
' Create a transformation atrix for rotating

' through angle theta around a line passing
' through (p1, p2, p3) in direction <dl, d2, d3>.
' Theta is measured counterclockwise as you look 
' down the line opposite the line's direction.
Private Sub m3LineRotate(M() As Single, ByVal p1 As Single, _
    ByVal p2 As Single, ByVal p3 As Single, _
    ByVal d1 As Single, ByVal d2 As Single, _
      ByVal d3 As Single, ByVal theta As Single)
Dim T(1 To 4, 1 To 4) As Single        ' Translate.
Dim R1(1 To 4, 1 To 4) As Single       ' Rotate 1.
Dim R2(1 To 4, 1 To 4) As Single       ' Rotate 2.
Dim Rot3(1 To 4, 1 To 4) As Single     ' Rotate.
Dim R2i(1 To 4, 1 To 4) As Single      ' Unrotate 2.
Dim R1i(1 To 4, 1 To 4) As Single      ' Unrotate 1.
Dim Ti(1 To 4, 1 To 4) As Single       ' Untranslate.
Dim D As Single
Dim L As Single
Dim M12(1 To 4, 1 To 4) As Single
Dim M34(1 To 4, 1 To 4) As Single
Dim M1234(1 To 4, 1 To 4) As Single

 
< previous page page_452 next page >